# 捕获异常
try:
    f = open('aa.txt', 'r', encoding='utf-8')
except:
    print('报错啦！！！')
    f = open('aa.txt', 'w', encoding='utf-8')

# 捕获多个异常
# 捕获指定的异常
try:
    # print(name)
    1 / 0
except (NameError, ZeroDivisionError) as name:
    print(name)

# 捕获所有异常
try:
    print(name)
except Exception as error:
    print(error)
else:
    print('没异常，好高兴')
finally:
    print('无论如何都会执行')

# 异常具有传递性
def fn1():
    print(name)

def fn2():
    fn1()

def main():
    try:
        fn2()
    except Exception as error:
        print(error)

main()